<?php
declare(strict_types=1);

use App\Client\HomeApp;
use App\Client\WebhookApp;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\App;
use Slim\Interfaces\RouteCollectorProxyInterface as Group;

return function (App $app) {
    $app->options('/{routes:.*}', function (Request $request, Response $response) {
        // CORS Pre-Flight OPTIONS Request Handler
        return $response;
    });

    $app->get('/hello', function (Request $request, Response $response) {
        $response->getBody()->write('Hello world!');
        return $response;
    });

    $app->post('/webhook', WebhookApp::class . ':webhook');

    $app->group('/', function (Group $group) {
        $group->get('', HomeApp::class . ':home');
        $group->get('add', HomeApp::class . ':addPage');
        $group->post('add', HomeApp::class . ':addSubmit');
    });
};